package com.xxx.user.controller;

import com.xxx.entity.Result;
import com.xxx.entity.StatusCode;
import com.xxx.user.domain.User;
import com.xxx.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author blijojo
 * @date 2021/6/20
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{userId}")
    public Result findById(@PathVariable("userId") String userId) {
        User user = userService.getById(userId);
        return new Result(StatusCode.OK, true, "查询成功", user);
    }

    /**
     * 查询所有用户id
     */
    @GetMapping()
    public Result findAllId() {
        List<String> ids = userService.findIds();
        return new Result(StatusCode.OK, true, "查询成功", ids);
    }

}
